<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=yes" name="format-detection" />
    <link href="css/index.css" rel="stylesheet" type="text/css">
    <link href="css/registered.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/layer/layer.js"></script>
    <script src="js/jquery.md5.js"></script>
</head>
<body>
<div class="viewport">
    <div class="header">
        <div class="header-1"><a href="Login.html"><img src="images/u15.png"></a></div>
        <div class="header-2">注册企业用户</div>
        <div class="header-3"><div class="header-3-1"></div> </div>
    </div>
    <div class="blank"></div>
    <div class="content">
        <div class="content-1"><a href="registered.html"><span>个人用户注册</span><img src="images/u33.png"></a> </div>
        <div class="content3-1">
            <div class="content3-1-1"><input type="checkbox" id="check1"><span>购销商</span></div>
            <div class="content3-1-2"><input type="checkbox" id="check2"><span>餐饮企业</span></div>
        </div>
        <div class="content3-2"><input type="text" placeholder="请输入单位名称" id="company" maxlength="30px"></div>
        <div class="content3-2"><input type="text" placeholder="请输入手机号" id="cellphone" maxlength="15px"></div>
        <div class="content3-2"><input type="text" placeholder="请输入验证码" class="input3" id="c-code" maxlength="6px"><span id="yzm" class="yam" onclick="document.getElementById('yzm').innerHTML = yzm();" onload="createCode()"></span></div>
        <div class="content3-2"><input type="text" placeholder="输入管理员姓名" id="adminName" maxlength="30px"></div>
        <div class="content3-2"><input type="password" placeholder="设置密码" id="password" maxlength="30px"></div>
        <div class="content3-2"><input type="password" placeholder="确认密码" id="again" maxlength="30px"></div>
        <div class="content-7"><input type="button" value="提 交" id="submit"></div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var fss=function(){
        var arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
        var str = '';
        for(var i = 0 ; i < 4 ; i ++ )
            str += ''+arr[Math.floor(Math.random() * arr.length)];
        $("#yzm").text(str);
    };
    $(function(){
        fss()
    });
    function yzm(){
        var arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
        var str = '';
        for(var i = 0 ; i < 4 ; i ++ )
            str += ''+arr[Math.floor(Math.random() * arr.length)];
        return str;
    }
    $(function(){
        $("#protocol").click(function(){
            layer.open({
                type:2,
                title:"《快来网络用户注册协议》",
                shadeClose:true,
                shade:0.2,
                area:["90%","60%"],
                content:"UserAgreement.html"
            })
        })
    });
    /*企业用户*/
    $(function(){
        $("#submit").click(function(){
            var check1=$("#check1").prop("checked");
            var check2=$("#check2").prop("checked");
            var companyName=$("#company").val();
            var cellphone=$("#cellphone").val();
            var Patrn =/^1[3,5,8]\d{9}$/;
            var Code=$("#c-code").val().toUpperCase();
            var yzm=$("#yzm").text();
            var adminName=$("#adminName").val();
            var password=$("#password").val();
            var again=$("#again").val();
            if(check1==""&&check2==""){
                layer.msg("请勾选企业性质",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(companyName==""){
                layer.msg("请输入单位名称",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(cellphone==""){
                layer.msg("请输入手机号",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(!Patrn.test(cellphone)){
                layer.msg("请输入正确格式手机号",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(Code==""){
                layer.msg("请输入验证码",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(Code.length<4){
                layer.msg("验证码少于4位字符",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(Code.length>4){
                layer.msg("验证码大于于4位字符",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(Code!=yzm){
                layer.msg("验证码错误",{shadeClose:true,shade:0.1,time:2000});
                fss()
            }
            else if(adminName==""){
                layer.msg("请输入管理员姓名",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(password==""){
                layer.msg("请输入密码",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(password.length<6){
                layer.msg("密码不能少于6个字符",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(password.length>20){
                layer.msg("密码不能大于20个字符",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(!password.match(/^[a-zA-Z]\w{5,19}$/)){
                layer.msg("密码请以字母开头，只能包含字母、数字和下划线",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(again==""){
                layer.msg("请再次输入密码",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(password!=again){
                layer.msg("两次输入的密码不一致",{shadeClose:true,shade:0.1,time:2000});
            }
            else{
                var index =layer.load(2,{content:"loading..."});
                $.ajax({
                    type:"post",
                    url:"/nsy-web/api/card/centerService",
                    data:{
                        serviceCode:"6002",
                        sign:"5f9e152adc8953f31487140d6c0982a590b2ca10",
                        timestamp:"20160627111123",
                        nonce:"123456789",
                        editUser:"zhangsan",
                        editTime:"2016-06-27%2011:11:27",
                        companyName:companyName
                    },
                    success:function(data){
                        var a = eval("("+data+")");
                        if(a.returnCode=="200"){
                            alert(1)
                        }
                        else if(a.returnCode=="00998"){
                            layer.close(index);
                            layer.msg("参数错误",{shadeClose:true,shade:0.1,time:2000});
                        }
                        else if(a.returnCode=="20020"){
                            layer.close(index);
                            layer.msg("账号已存在",{shadeClose:true,shade:0.1,time:2000});
                        }
                        else{
                            layer.close(index);
                            layer.msg("注册失败",{shadeClose:true,shade:0.1,time:2000});
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("error")
                    }
                });
            }
        })
    })
</script>
